/*
 * @Author: zqx me_zqx@163.com
 * @Date: 2025-04-09 11:36:55
 * @LastEditors: zqx me_zqx@163.com
 * @LastEditTime: 2025-09-09 11:26:15
 * @FilePath: /XMate-h5/src/utils/platformTool.js
 * @Description: 这是默认设置,请设置`customMade`, 打开koroFileHeader查看配置 进行设置: https://github.com/OBKoro1/koro1FileHeader/wiki/%E9%85%8D%E7%BD%AE
 */
const isPC = function () {
  const userAgent = navigator.userAgent;

  const mobileKeywords = [
    "Mobi",
    "Android",
    "iPhone",
    "iPad",
    "Windows Phone",
    "Tablet",
    "Mobile"
  ];

  // 检查用户代理字符串中是否包含移动设备的关键字
  let isMobile = false;
  for (let i = 0; i < mobileKeywords.length; i++) {
    if (userAgent.indexOf(mobileKeywords[i]) !== -1) {
      isMobile = true; // 包含移动设备的关键字，不是PC
    }
  }
  return !isMobile;
};

// 是否为绚星会议App - isElectron
const isElectron = function () {
  if (
    typeof process !== "undefined" &&
    process.versions &&
    process.versions.electron
  ) {
    return true;
  }
  return false;
};

function getPlatform() {
  const userAgent = navigator?.userAgent || navigator.vendor || window.opera;

  // 检测 iOS 设备
  if (/iPad|iPhone|iPod/.test(userAgent) && !window.MSStream) {
    return "iOS";
  }

  // 检测 Android 设备
  if (/android/i.test(userAgent)) {
    return "Android";
  }

  // 检测 Windows 设备
  if (/win/i.test(userAgent)) {
    return "Windows";
  }

  // 检测 Mac 设备
  if (/mac/i.test(userAgent)) {
    return "mac";
  }

  // 默认返回 unknown 或其他你想要的默认值
  return "unknown";
}

function isWindows() {
  return getPlatform() === "Windows";
}

function isIOS() {
  return getPlatform() === "iOS";
}

function isMac() {
  return getPlatform() === "mac";
}

function isAndroid() {
  return getPlatform() === "Android";
}

const isInIframe = () => {
  try {
    return window.self !== window.top;
  } catch (e) {
    return true;
  }
};

export { isPC, isElectron, getPlatform, isWindows, isMac, isIOS, isAndroid, isInIframe };
